//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "CubicInterpolation.h"
using namespace Cephei::QL::Math::Interpolations;
#include <gen/QL/Math/Interpolation.h>
using namespace Cephei::QL::Math;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Interpolations::CCubicInterpolation::CCubicInterpolation (boost::shared_ptr<QuantLib::CubicInterpolation>& childNative, Object^ owner) : CInterpolation(CCubicInterpolation::typeid)
{
#ifdef HANDLE
	_phCubicInterpolation = NULL;
#endif
	_ppCubicInterpolation = &childNative;
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppCubicInterpolation));
}
Cephei::QL::Math::Interpolations::CCubicInterpolation::CCubicInterpolation (QuantLib::CubicInterpolation& childNative, Object^ owner) : CInterpolation(CCubicInterpolation::typeid)
{
#ifdef HANDLE
	_phCubicInterpolation = NULL;
#endif
	_ppCubicInterpolation = new boost::shared_ptr<QuantLib::CubicInterpolation> (&childNative);
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppCubicInterpolation));
    _CubicInterpolationOwner = owner;
    _InterpolationOwner = owner;
}

Cephei::QL::Math::Interpolations::CCubicInterpolation::CCubicInterpolation (CCubicInterpolation^ copy) : CInterpolation(CCubicInterpolation::typeid)
{
#ifdef HANDLE
	_phCubicInterpolation = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppCubicInterpolation = new boost::shared_ptr<QuantLib::CubicInterpolation> (copy->GetShared());
        _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppCubicInterpolation));
    }
}
Cephei::QL::Math::Interpolations::CCubicInterpolation::CCubicInterpolation (System::Type^ t) : CInterpolation(CCubicInterpolation::typeid)
{
#ifdef HANDLE
	_phCubicInterpolation = NULL;
#endif
	if (!t->IsSubclassOf(CCubicInterpolation::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Interpolations::CCubicInterpolation::CCubicInterpolation (QuantLib::Handle<QuantLib::CubicInterpolation>& childNative, Object^ owner)  : CInterpolation(CCubicInterpolation::typeid)
{
	_phCubicInterpolation = &childNative;
	_ppCubicInterpolation = &static_cast<boost::shared_ptr<QuantLib::CubicInterpolation>>(childNative.currentLink());
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppCubicInterpolation));
    _CubicInterpolationOwner = owner;
}
Cephei::QL::Math::Interpolations::CCubicInterpolation::CCubicInterpolation (QuantLib::Handle<QuantLib::CubicInterpolation> childNative)  : CInterpolation(CCubicInterpolation::typeid)
{
	_phCubicInterpolation = &childNative;
	_ppCubicInterpolation = &static_cast<boost::shared_ptr<QuantLib::CubicInterpolation>>(childNative.currentLink());
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppCubicInterpolation));
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Interpolations::CCubicInterpolation::CCubicInterpolation (QuantLib::CubicInterpolation childNative)  : CInterpolation(CCubicInterpolation::typeid)
{
#ifdef HANDLE
	_phCubicInterpolation = NULL;
#endif
	_ppCubicInterpolation = new boost::shared_ptr<QuantLib::CubicInterpolation> (new QuantLib::CubicInterpolation (childNative));
    _ppInterpolation = new boost::shared_ptr<QuantLib::Interpolation> (boost::dynamic_pointer_cast<QuantLib::Interpolation> (*_ppCubicInterpolation));
}
#endif

Cephei::QL::Math::Interpolations::CCubicInterpolation::~CCubicInterpolation ()
{
    if (_ppCubicInterpolation != NULL)
    {
	    delete _ppCubicInterpolation;
        _ppCubicInterpolation = NULL;
    }
}
Cephei::QL::Math::Interpolations::CCubicInterpolation::!CCubicInterpolation ()
{
    if (_ppCubicInterpolation != NULL)
    {
	    delete _ppCubicInterpolation;
    }
}
QuantLib::CubicInterpolation& Cephei::QL::Math::Interpolations::CCubicInterpolation::GetReference ()
{
    if (_ppCubicInterpolation == NULL) throw gcnew NativeNullException ();
	return **_ppCubicInterpolation;
}
boost::shared_ptr<QuantLib::CubicInterpolation>& Cephei::QL::Math::Interpolations::CCubicInterpolation::GetShared ()
{
    if (_ppCubicInterpolation == NULL) throw gcnew NativeNullException ();
	return *_ppCubicInterpolation;
}
QuantLib::CubicInterpolation* Cephei::QL::Math::Interpolations::CCubicInterpolation::GetPointer ()
{
    if (_ppCubicInterpolation == NULL) throw gcnew NativeNullException ();
	return &**_ppCubicInterpolation;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::CubicInterpolation>& Cephei::QL::Math::Interpolations::CCubicInterpolation::GetHandle ()
{
	if (_phCubicInterpolation == NULL)
	{
		_phCubicInterpolation = new Handle<QuantLib::CubicInterpolation> (*_ppCubicInterpolation);
	}
	return *_phCubicInterpolation;
}
#endif
bool Cephei::QL::Math::Interpolations::CCubicInterpolation::HasNative () 
{
	return (_ppCubicInterpolation != NULL);
}

Cephei::IVector<Double>^ Cephei::QL::Math::Interpolations::CCubicInterpolation::ACoefficients::get ()
{
    try
    {
    	std::vector<QuantLib::Real>& _rv = (std::vector<QuantLib::Real>&)(*_ppCubicInterpolation)->aCoefficients ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Math::Interpolations::CCubicInterpolation::BCoefficients::get ()
{
    try
    {
    	std::vector<QuantLib::Real>& _rv = (std::vector<QuantLib::Real>&)(*_ppCubicInterpolation)->bCoefficients ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Math::Interpolations::CCubicInterpolation::CCoefficients::get ()
{
    try
    {
    	std::vector<QuantLib::Real>& _rv = (std::vector<QuantLib::Real>&)(*_ppCubicInterpolation)->cCoefficients ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Boolean>^ Cephei::QL::Math::Interpolations::CCubicInterpolation::MonotonicityAdjustments::get ()
{
    try
    {
    	std::vector<bool>& _rv = (std::vector<bool>&)(*_ppCubicInterpolation)->monotonicityAdjustments ( );   
        Cephei::IVector<Boolean>^ _nrv = gcnew CoVector<Boolean> (gcnew CBooleanVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::IVector<Double>^ Cephei::QL::Math::Interpolations::CCubicInterpolation::PrimitiveConstants::get ()
{
    try
    {
    	std::vector<QuantLib::Real>& _rv = (std::vector<QuantLib::Real>&)(*_ppCubicInterpolation)->primitiveConstants ( );   
        Cephei::IVector<Double>^ _nrv = gcnew CoVector<Double> (gcnew CDoubleVector (_rv));
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

